package ClassExercise1;

import java.util.Scanner;

public class ExerciseClass {

    public static void main(String[] args) {
        Scanner sr = new Scanner(System.in);
        boolean count = false;
        System.out.println("1:用户类型选择");
        System.out.println("2:单个用户租金计算");
        System.out.println("3:多用户租金计算");
        System.out.println("4:退出程序：");
        while (true) {
            if (count) {
                count = false;
                isContined();
            } else {
                System.out.println("请输入1-4:");
            }
            int c = sr.nextInt();
            //如果输入的数字不是1-4则继续输入
            if ((c != 1) && (c != 4) && (c != 2) && (c != 3)) {
                System.out.println("------------------------");
                System.out.println("1:用户类型选择");
                System.out.println("2:单个用户租金计算");
                System.out.println("3:多用户租金计算");
                System.out.println("4:退出程序：");
            }
            //若符合1-3则进入switch
            if (c == 1 || c == 2 || c == 3) {
                for(;;){
                    if (c != 2 && c != 3 && c != 4) {
                        System.out.println("------------------------");
                        System.out.println("2:单个用户租金计算");
                        System.out.println("3:多用户租金计算");
                        System.out.println("4:退出程序：");
                        System.out.print("请输入2-4：");
                        c = sr.nextInt();
                    }else{
                        break;
                    }
                }
                switch(c) {
                    case 2:
                        simplePerson();
                        count = true;
                        break;
                    case 3:
                        people();
                        count = true;
                        break;
                    case 4:
                        System.out.println("程序结束");
                        System.exit(1);
                }
            } else if (c == 4) {
                System.out.println("程序结束");
                break;
            }
        }
    }

    //单个客户
    public static void simplePerson() {
        System.out.println("欢饮选择单个客户计算租金!");
        Scanner sr = new Scanner(System.in);
        double arr[] = new double[3];
        System.out.println(" 请输入基本入住租金：");
        arr[0] = sr.nextDouble();
        System.out.println("请输入本月电费:");
        arr[1] = sr.nextDouble();
        System.out.println("请输入本月水费：");
        arr[2] = sr.nextDouble();
        System.out.println("您本月应该交的租金为：" + (arr[0] + arr[1] + arr[2]));
    }

    //多个客户
    public static void people() {
        System.out.println("欢饮选择多个客户计算租金!");
        Scanner sr = new Scanner(System.in);
        System.out.println("请输入人数：");
        int N = sr.nextInt();
        double[][] arr1 = new double[N][3];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j <= 0; j++) {
                System.out.println("请输入第" + (i + 1) + "名顾客需要交的租金");
                System.out.println(" 请输入基本入住租金：");
                arr1[i][0] = sr.nextDouble();
                System.out.println("请输入本月电费:");
                arr1[i][1] = sr.nextDouble();
                System.out.println("请输入本月水费：");
                arr1[i][2] = sr.nextDouble();
            }
        }
        for (int k = 0; k < N; k++) {
            System.out.println("第" + (k + 1) + "位客户所需要交的资金为：" + (arr1[k][0] + arr1[k][1] + arr1[k][2]));
        }
    }

    //判断是否继续使用
    public static void isContined() {
        Scanner sr = new Scanner(System.in);
        System.out.println("请问您是否继续？输入S：继续、输入其他:退出 ");
        String temp = sr.next();
        if ("s".equalsIgnoreCase(temp)) {
            System.out.println("*******************");
            System.out.println("请输入1-4:");
            System.out.println("1:用户类型选择");
            System.out.println("2:单个用户租金计算");
            System.out.println("3:多用户租金计算");
            System.out.println("4:退出程序：");
        } else {
            System.out.println("程序结束！谢谢使用！");
            System.exit(1);
        }
    }
}
